package com.kotlin.book.api

import HttpApi
import com.google.gson.reflect.TypeToken
import com.kotlin.book.entry.Type

object TypeApi {
    fun getHomeType(
        param: Map<String, Any?>?,
        callback: (HttpApi.ApiResponse<List<Type>>?) -> Unit
    ) {
        val type = object : TypeToken<HttpApi.ApiResponse<List<Type>>>() {}.type
        HttpApi.get<List<Type>>(
            "/type/getHomeType",
            param ?: mapOf(),
            type
        ) { response ->
            response?.let { callback(it) } ?: callback(null)
        }
    }

    fun getClassType(
        param: Map<String, Any?>?,
        callback: (HttpApi.ApiResponse<List<Type>>?) -> Unit
    ) {
        val type = object : TypeToken<HttpApi.ApiResponse<List<Type>>>() {}.type
        HttpApi.get<List<Type>>(
            "/type/getClassType",
            param ?: mapOf(),
            type
        ) { response ->
            response?.let { callback(it) } ?: callback(null)
        }
    }
}